//
//  TheMaterialSearchViewController.m
//  OrderAssistant
//
//  Created by chendong on 2020/8/26.
//  Copyright © 2020 chendong. All rights reserved.
//

#import "TheMaterialSearchViewController.h"
#import "TheMaterialSearchTableViewCell.h"
#import <SVProgressHUD.h>
#import "CargoBoxViewController.h"
@interface TheMaterialSearchViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property(nonatomic,strong) UITableView *myTableView;
@property (nonatomic,strong) UITextField *wlssBtn;
@property (nonatomic,strong) NSMutableArray *otherARR;
@property (nonatomic,strong) NSMutableArray *finalotherARR;

@property (nonatomic,strong) UIView *mbV;
@property (nonatomic,strong) UIView *srBgV;
@property (nonatomic,strong) UITextField *srBgVTF;
@property (nonatomic,strong) UILabel *wlL;
@property (nonatomic,strong) TheMaterialSearchTableViewCell *wlLCell;
@property (nonatomic,strong) UILabel *jbL;
@property (nonatomic,strong) UIView *rightVVV;
@property (nonatomic,strong) UITextField *tffff;
@property (nonatomic,assign) BOOL isTffff;
@property (nonatomic,strong) UIButton *gwcBtn;
@end

@implementation TheMaterialSearchViewController
-(UIView *)mbV{
    if (!_mbV) {
        _mbV = [[UIView alloc]initWithFrame:self.view.bounds];
        _mbV.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [self.view.window addSubview:_mbV];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(mbVAction:)];
        [_mbV addGestureRecognizer:tap];
    }
    return _mbV;
}
-(void)mbVAction:(UITapGestureRecognizer *)tap{
//    self.mbV.hidden = YES;
//    self.srBgV.hidden = YES;
    [self.view endEditing:YES];
}
-(UIView *)srBgV{
    if (!_srBgV) {
        _srBgV = [[UIView alloc]initWithFrame:CGRectMake(50, 0, SCREENWIDTH-100, 200)];
        _srBgV.center = CGPointMake(SCREENWIDTH/2, SCREENHEIGHT/2);
        _srBgV.backgroundColor = [UIColor whiteColor];
        _srBgV.layer.cornerRadius = 5;
        _srBgV.clipsToBounds = YES;
        [self.view.window addSubview:_srBgV];
        UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, _srBgV.frame.size.width, 50)];
        titleL.text = @"请输入数量";
        titleL.font = [UIFont systemFontOfSize:20];
        titleL.textAlignment = NSTextAlignmentCenter;
        [_srBgV addSubview:titleL];
        self.wlL = titleL;
        UILabel *slL = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(titleL.frame), 0, 50)];
        slL.text = @"数量";
        [_srBgV addSubview:slL];
        UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(slL.frame), CGRectGetMaxY(titleL.frame), _srBgV.frame.size.width-10-CGRectGetMaxX(slL.frame), 50)];
        tf.keyboardType = UIKeyboardTypeDecimalPad;
        tf.layer.borderWidth = 1;
        tf.layer.borderColor = [UIColor lightGrayColor].CGColor;
        tf.layer.cornerRadius = 5;
        tf.clipsToBounds = YES;
        tf.placeholder = @"请输入数量";
        tf.delegate = self;
        self.tffff = tf;
        UIView *lV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 50)];
        tf.leftView = lV;
        tf.leftViewMode = UITextFieldViewModeAlways;
        [_srBgV addSubview:tf];
        self.srBgVTF = tf;
        UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cancleBtn.frame = CGRectMake(10, CGRectGetMaxY(tf.frame)+15, _srBgV.frame.size.width/2-20, 40);
        cancleBtn.layer.cornerRadius = 5;
        cancleBtn.clipsToBounds = YES;
        [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cancleBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_srBgV addSubview:cancleBtn];
        [cancleBtn addTarget:self action:@selector(cancleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        quedingBtn.frame = CGRectMake(CGRectGetMaxX(cancleBtn.frame)+20, CGRectGetMaxY(tf.frame)+15, _srBgV.frame.size.width/2-20, 40);
        quedingBtn.layer.cornerRadius = 5;
        quedingBtn.clipsToBounds = YES;
        [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
        [quedingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        quedingBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_srBgV addSubview:quedingBtn];
        [quedingBtn addTarget:self action:@selector(quedingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _srBgV;
}
-(void)cancleBtnAction:(UIButton *)btn{
    self.mbV.hidden = YES;
    self.srBgV.hidden = YES;
    self.srBgVTF.text = @"";
    [self.view.window endEditing:YES];
    if (self.yjDataArr.count == 0) {
        self.jbL.hidden = YES;
        self.gwcBtn.enabled = NO;
    }else{
        self.jbL.hidden = NO;
        self.gwcBtn.enabled = YES;
    }
}
-(void)quedingBtnAction:(UIButton *)btn{
    [self.view.window endEditing:YES];
    if (self.srBgVTF.text.length <= 0) {
        self.srBgVTF.text = @"";
        self.mbV.hidden = YES;
        self.srBgV.hidden = YES;
        return;
    }
    if ([self.srBgVTF.text hasSuffix:@"."]) {
        self.srBgVTF.text = [[self.srBgVTF.text componentsSeparatedByString:@"."] firstObject];
    }
    for (int i=0; i<self.yjDataArr.count; i++) {
        if ([[NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialID"]] isEqualToString:[NSString stringWithFormat:@"%@",self.yjDataArr[i][@"MaterialID"]]]) {
            NSDictionary *ddd = self.yjDataArr[i];
            
            NSDictionary *d = self.wlLCell.dic;
            NSDictionary *dd = self.houseDic;
            NSString *IsUseAuxiliaryUnit = [NSString stringWithFormat:@"%@",dd[@"IsUseAuxiliaryUnit"]];
            int bl = [[[[NSString stringWithFormat:@"%@",d[@"ConvertUnit"]] componentsSeparatedByString:@":"] firstObject] floatValue];
            if ([IsUseAuxiliaryUnit isEqualToString:@"1"]) {
                if ([self.srBgVTF.text intValue]%bl == 0) {
                    
                }else{
                    NSString *finS = [NSString stringWithFormat:@"%d",([self.srBgVTF.text intValue]/bl + 1)*bl];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@的数量必须是%d的倍数",self.wlLCell.dic[@"MaterialName"],bl]];
                    self.srBgVTF.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
                }
            }
            
            [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
            if ([self.srBgVTF.text isEqualToString:@"0"]) {
                [self.yjDataArr removeObject:self.yjDataArr[i]];
                self.jbL.text = [NSString stringWithFormat:@"%ld",self.yjDataArr.count];
                self.jbL.hidden = NO;
                if (self.yjDataArr.count == 0) {
                    self.jbL.hidden = YES;
                }
            }
            break;
        }
        if (i==self.yjDataArr.count-1 && ![self.srBgVTF.text isEqualToString:@"0"]) {
            NSDictionary *ddd = self.wlLCell.dic;
            
            NSDictionary *dd = self.houseDic;
            NSString *IsUseAuxiliaryUnit = [NSString stringWithFormat:@"%@",dd[@"IsUseAuxiliaryUnit"]];
            int bl = [[[[NSString stringWithFormat:@"%@",ddd[@"ConvertUnit"]] componentsSeparatedByString:@":"] firstObject] floatValue];
            if ([IsUseAuxiliaryUnit isEqualToString:@"1"]) {
                if ([self.srBgVTF.text intValue]%bl == 0) {
                    
                }else{
                    NSString *finS = [NSString stringWithFormat:@"%d",([self.srBgVTF.text intValue]/bl + 1)*bl];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@的数量必须是%d的倍数",self.wlLCell.dic[@"MaterialName"],bl]];
                    self.srBgVTF.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
                }
            }
            
            [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
            [self.yjDataArr addObject:ddd];
            self.jbL.text = [NSString stringWithFormat:@"%ld",self.yjDataArr.count];
            self.jbL.hidden = NO;
            if (self.yjDataArr.count == 0) {
                self.jbL.hidden = YES;
            }
        }
    }
    if (self.yjDataArr.count == 0 && ![self.srBgVTF.text isEqualToString:@"0"]) {
        NSDictionary *ddd = self.wlLCell.dic;
        
        NSDictionary *dd = self.houseDic;
        NSString *IsUseAuxiliaryUnit = [NSString stringWithFormat:@"%@",dd[@"IsUseAuxiliaryUnit"]];
        int bl = [[[[NSString stringWithFormat:@"%@",ddd[@"ConvertUnit"]] componentsSeparatedByString:@":"] firstObject] floatValue];
        if ([IsUseAuxiliaryUnit isEqualToString:@"1"]) {
            if ([self.srBgVTF.text intValue]%bl == 0) {
                
            }else{
                NSString *finS = [NSString stringWithFormat:@"%d",([self.srBgVTF.text intValue]/bl + 1)*bl];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@的数量必须是%d的倍数",self.wlLCell.dic[@"MaterialName"],bl]];
                self.srBgVTF.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
            }
        }
        [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
        [self.yjDataArr addObject:ddd];
        self.jbL.text = [NSString stringWithFormat:@"%ld",self.yjDataArr.count];
        self.jbL.hidden = NO;
        if (self.yjDataArr.count == 0) {
            self.jbL.hidden = YES;
        }
    }
    self.srBgVTF.text = @"";
    self.mbV.hidden = YES;
    self.srBgV.hidden = YES;
    self.wlssBtn.text = @"";
    [self changedTextField:self.wlssBtn];
    [self.wlssBtn becomeFirstResponder];
    if (self.yjDataArr.count == 0) {
        self.jbL.hidden = YES;
        self.gwcBtn.enabled = NO;
    }else{
        self.jbL.hidden = NO;
        self.gwcBtn.enabled = YES;
    }
    
//    NSDictionary *d = self.wlLCell.dic;
//    NSDictionary *dd = self.houseDic;
//    NSString *IsUseAuxiliaryUnit = [NSString stringWithFormat:@"%@",dd[@"IsUseAuxiliaryUnit"]];
//    int bl = [[[[NSString stringWithFormat:@"%@",d[@"ConvertUnit"]] componentsSeparatedByString:@":"] firstObject] floatValue];
//    if ([IsUseAuxiliaryUnit isEqualToString:@"1"]) {
//        if ([self.srBgVTF.text intValue]%bl == 0) {
//            self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":self.srBgVTF.text;
//        }else{
//            NSString *finS = [NSString stringWithFormat:@"%d",([self.srBgVTF.text intValue]/bl + 1)*bl];
//            self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
//
//            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
//            [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
//            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@的数量必须是%d的倍数",self.wlLCell.dic[@"MaterialName"],bl]];
//
//            self.srBgVTF.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
//        }
//    }else{
//        self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":self.srBgVTF.text;
//    }
    
    [self creatPlist];
}
-(NSMutableArray *)finalotherARR{
    if (!_finalotherARR) {
        _finalotherARR = [[NSMutableArray alloc]init];
    }
    return _finalotherARR;
}
-(NSMutableArray *)otherARR{
    if (!_otherARR) {
        _otherARR = [[NSMutableArray alloc]init];
    }
    return _otherARR;
}
-(void)setDataArr:(NSMutableArray *)dataArr{
    _dataArr = dataArr;
    for (int i=0; i<dataArr.count; i++) {
        NSArray *a = dataArr[i][@"MaterialInfs"];
        [self.otherARR addObjectsFromArray:a];
        [self.finalotherARR addObjectsFromArray:a];
    }
}
-(UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.wlssBtn.frame)+5, SCREENWIDTH, SCREENHEIGHT-CGRectGetMaxY(self.wlssBtn.frame)-5) style:UITableViewStylePlain];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
//        _myTableView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}
-(void)rightAction:(UIButton *)item{
    if (self.yjDataArr.count == 0) {
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
        [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"您还没有添加物料！"];
    }else{
        CargoBoxViewController *cbVC = [[CargoBoxViewController alloc]init];
        cbVC.dataMarr = self.yjDataArr;
        cbVC.userDic = self.userDic;
        cbVC.houseDic = self.houseDic;
        [self.navigationController pushViewController:cbVC animated:YES];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"物料搜索";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *rightV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    UIButton *gwcBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    gwcBtn.frame = CGRectMake(5, 5, 40, 40);
    [gwcBtn setImage:[UIImage imageNamed:@"五一路凉菜库_10.png"] forState:UIControlStateNormal];
    gwcBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [gwcBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    [rightV addSubview:gwcBtn];
    gwcBtn.enabled = self.yjDataArr.count==0?NO:YES;
    self.gwcBtn = gwcBtn;
    UILabel *jbL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    jbL.center = CGPointMake(CGRectGetMaxX(gwcBtn.frame)-10, 10);
    jbL.layer.cornerRadius = 10;
    jbL.clipsToBounds = YES;
    jbL.textAlignment = NSTextAlignmentCenter;
    jbL.font = [UIFont systemFontOfSize:10];
    jbL.textColor = [UIColor whiteColor];
    jbL.backgroundColor = RGBCOLOR(251, 62, 31);
    jbL.text = [NSString stringWithFormat:@"%ld",self.yjDataArr.count];
    jbL.hidden = self.yjDataArr.count==0?YES:NO;
    [rightV addSubview:jbL];
    self.jbL = jbL;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightV];
    
    UIView *leftV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    UIButton *gwcBtnl = [UIButton buttonWithType:UIButtonTypeCustom];
    gwcBtnl.frame = CGRectMake(0, 5, 30, 30);
    gwcBtnl.userInteractionEnabled = NO;
    [gwcBtnl setImage:[UIImage imageNamed:@"货框_03.png"] forState:UIControlStateNormal];
    gwcBtnl.imageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *t = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftAction:)];
    [leftV addGestureRecognizer:t];
//    [gwcBtnl addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    [leftV addSubview:gwcBtnl];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftV];
    
    
    UITextField *wlssBtn = [[UITextField alloc]initWithFrame:CGRectMake(5, kNavBarAndStatusBarHeight+5, SCREENWIDTH-10, 50)];
    wlssBtn.delegate = self;
    wlssBtn.layer.cornerRadius = 5;
    wlssBtn.clipsToBounds = YES;
    wlssBtn.layer.borderWidth = 1;
    wlssBtn.layer.borderColor = RGBCOLOR(200, 200, 200).CGColor;
    wlssBtn.placeholder = @"物料助记符/名称";
    UIView *rightVVV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    rightVVV.hidden = YES;
    self.rightVVV = rightVVV;
    UIImageView *rigTFV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
    rigTFV.image = [UIImage imageNamed:@"shanchu.png"];
    [rightVVV addSubview:rigTFV];
    wlssBtn.rightView = rightVVV;
    wlssBtn.rightViewMode = UITextFieldViewModeAlways;
    rigTFV.userInteractionEnabled = YES;
    UITapGestureRecognizer *tttt = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ttttAction:)];
    [rigTFV addGestureRecognizer:tttt];
    UIView *leftVVV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 50)];
    UIImageView *lefTFV = [[UIImageView alloc]initWithFrame:CGRectMake(5, 10, 30, 30)];
    lefTFV.image = [UIImage imageNamed:@"fangdajing.png"];
    [leftVVV addSubview:lefTFV];
    wlssBtn.leftView = leftVVV;
    wlssBtn.leftViewMode = UITextFieldViewModeAlways;
    [self.view addSubview:wlssBtn];
    self.wlssBtn = wlssBtn;
//    UIView *tfLeftV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
//    wlssBtn.leftView = tfLeftV;
//    wlssBtn.leftViewMode = UITextFieldViewModeAlways;
    
    [wlssBtn addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];

    [self myTableView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeActionL:) name:@"changeee" object:nil];
    
    
}
-(void)ttttAction:(UITapGestureRecognizer *)tap{
    self.rightVVV.hidden = YES;
    self.wlssBtn.text = @"";
    [self.view endEditing:YES];
    [self.otherARR removeAllObjects];
    [self.otherARR addObjectsFromArray:self.finalotherARR];
    [self.myTableView reloadData];
}
-(void)leftAction:(UITapGestureRecognizer *)item{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeee" object:nil];
    [self.navigationController popViewControllerAnimated:YES];
    
}
-(void)changeActionL:(NSNotification *)not{
    self.jbL.text = [NSString stringWithFormat:@"%ld",self.yjDataArr.count];
    if (self.yjDataArr.count == 0) {
        self.jbL.hidden = YES;
    }else{
        self.jbL.hidden = NO;
    }
}
#pragma mark -给每个cell中的textfield添加事件，只要值改变就调用此函数
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField == self.tffff) {
        [self.srBgVTF performSelector:@selector(selectAll:) withObject:nil afterDelay:.0f];
    }
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == self.tffff && self.isTffff) {
        textField.text = @"";
        self.isTffff = NO;
    }
    if (textField == self.srBgVTF) {
        if ([string isEqualToString:@"."]) {
            if (textField.text.length == 0 || [textField.text containsString:@"."]) {
                return NO;
            }
        }
    }
    return YES;
}
-(void)changedTextField:(id)textField
{
    NSString *testStr = [self.wlssBtn.text uppercaseString];
    [self.otherARR removeAllObjects];
    for (int i=0; i<self.finalotherARR.count; i++) {
        NSString *s1 = [NSString stringWithFormat:@"%@",self.finalotherARR[i][@"MaterialZJF"]];
        NSString *s2 = [NSString stringWithFormat:@"%@",self.finalotherARR[i][@"MaterialName"]];
        if ([s1 containsString:testStr] || [s2 containsString:testStr]) {
            [self.otherARR addObject:self.finalotherARR[i]];
        }
    }
    if (self.wlssBtn.text.length == 0) {
        [self.otherARR addObjectsFromArray:self.finalotherARR];
    }
    [self.myTableView reloadData];
    if (self.wlssBtn.text.length > 0) {
        self.rightVVV.hidden = NO;
    }else{
        self.rightVVV.hidden = YES;
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    return YES;
}
#pragma mark <UITableViewDelegate,UITableViewDataSource>
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *hhV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 50)];
        hhV.backgroundColor = RGBCOLOR(108, 185, 251);
        NSArray *arr = @[@"助记符",@"名称",@"规格",@"规格"];
        int x = 0;
        int y = 0;
        int w = SCREENWIDTH/arr.count;
        int h = 50;
        for (int i=0; i<arr.count; i++) {
            x = w*i;
            UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(x, y, w, h)];
            l.textAlignment = NSTextAlignmentCenter;
            l.textColor = [UIColor whiteColor];
            l.text = arr[i];
            [hhV addSubview:l];
        }
        return hhV;
    }else{
        return nil;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 50;
    }else{
        return 0.01f;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.otherARR.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *idf = @"TheMaterialSearchTableViewCell";
    TheMaterialSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idf];
    if (!cell) {
        cell = [[TheMaterialSearchTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
    }
    cell.dic = self.otherARR[indexPath.row];
    if (indexPath.row%2 == 0) {
        cell.backgroundColor = [UIColor whiteColor];
    }else{
        cell.backgroundColor = RGBCOLOR(246, 246, 246);
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.isTffff = YES;
    self.wlLCell = [tableView cellForRowAtIndexPath:indexPath];
    self.mbV.hidden = NO;
    self.srBgV.hidden = NO;
    self.wlL.text = [NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialName"]];

    for (int i=0; i<self.yjDataArr.count; i++) {
        if ([[NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialID"]] isEqualToString:[NSString stringWithFormat:@"%@",self.yjDataArr[i][@"MaterialID"]]]) {
            self.srBgVTF.text = [NSString stringWithFormat:@"%@",self.yjDataArr[i][@"MaterialNum"]];
            break;
        }
    }
    [self.srBgVTF becomeFirstResponder];
}
//1.创建plist文件
-(void)creatPlist{
    //1.创建plist文件的路径(plist文件要存储的本地路径)
    NSString *filePath = [NSHomeDirectory() stringByAppendingString:@"/Documents/myPlist.plist"];
   
    //2.准备存储的数据
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
   
    [dic setValue:self.houseDic forKey:@"ckHouse"]; //仓库选择
   
    [dic setValue:self.userDic forKey:@"userData"];//用户数据
   
    [dic setValue:self.yjDataArr forKey:@"numDataMarr"];//已点物料
   
    //3.将准备好的数据存储到plist文件中
    [dic writeToFile:filePath atomically:YES];
}
@end
